home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / presto / prest_04.lha / src / synchro.h < prev    next >
Encoding:
C/C++ Source or Header  |  1989-06-06  |  1.1 KB  |  66 lines

  1. //
  2. // Synchronization objects.
  3. //
  4.  
  5.  
  6. class SynchroObject : public Object {
  7.     Spinlock    *so_lock;
  8.     ThreadQUnlocked    *so_waiting;
  9. public:
  10.     SynchroObject(int t, char *name=0);
  11.     ~SynchroObject();
  12.     inline void remember(Thread* t);
  13.     inline Thread* recall();
  14.     inline void lock();            // always inline
  15.     inline void unlock();            // cyclic dependencies!
  16.     inline ThreadQUnlocked    *waitingQueue();
  17.     virtual void print(ostream& = cout);
  18. };
  19.  
  20. inline void
  21. SynchroObject::lock()
  22. {    
  23.     register Spinlock *sp = so_lock;
  24.      sp->lock();
  25. }
  26.  
  27. inline void
  28. SynchroObject::unlock()
  29. {
  30.     register Spinlock *sp = so_lock;
  31.     sp->unlock();
  32. }
  33.  
  34.  
  35.  
  36. inline
  37. Thread*
  38. SynchroObject::recall()
  39. {
  40.     register ThreadQUnlocked *soq = so_waiting;
  41.     return soq->get();
  42. }
  43.  
  44. inline
  45. void
  46. SynchroObject::remember(Thread *t)
  47. {
  48.     register ThreadQUnlocked *soq = so_waiting;
  49.     t->orstate(TS_BLOCKED);
  50.     //
  51.     // at this point, we are both blocked AND running.  We have been
  52.     // blocked as far as the queue is concerned, but we still need
  53.     // to sleep ourselves before we can be considered not running
  54.     //
  55.     soq->append(t);
  56. }
  57.  
  58. inline
  59. ThreadQUnlocked*
  60. SynchroObject::waitingQueue()
  61. {
  62.     return so_waiting;
  63. }
  64.  
  65.  
  66.